/**
 *
 */
package com.davetrudes.jung.client.graphics;

import com.davetrudes.jung.client.graphics.geom.AffineTransform;
import com.davetrudes.jung.client.graphics.impl.canvas.Canvas2DImplDefault;
import com.davetrudes.jung.client.graphics.impl.canvas.Canvas2DImplNoRender;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Image;

/**
 * @author dave.trudes
 *
 */
public class Canvas2D extends Graphics2D {

	//private final Graphics2D impl = new Canvas2DImplNoRender();
	private final Graphics2D impl = new Canvas2DImplDefault();
		//GWT.create(Graphics2D.class);
	private Element container;
	private int height, width;

	public Canvas2D(){
		this(0, 0);
	}

	public Canvas2D(int width, int height){
		this(width, height, null);
	}

	public Canvas2D(int width, int height, String style){
		container = DOM.createDiv();
		container.appendChild(impl.getElement());
		setElement(container);

		setWidth(width);
		setHeight(height);

		if (style != null){
			setStyleName(style);
		}
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#clearRect(int, int, int, int)
	 */
	@Override
	public void clearRect(int x, int y, int width, int height) {
		impl.clearRect(x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#clip(awt.client.Shape)
	 */
	@Override
	public void clip(Shape s) {
		impl.clip(s);
	}

	/* (non-Javadoc)
	 * @see com.davetrudes.jung.client.graphics.Graphics2D#drawComponent(com.davetrudes.jung.client.graphics.Component)
	 */
	@Override
	public void drawComponent(Component component) {
		impl.drawComponent(component);
	}
	
	

	/* (non-Javadoc)
	 * @see com.davetrudes.jung.client.graphics.Graphics2D#draw(com.davetrudes.jung.client.graphics.Component, int, int, int, int, boolean)
	 */
	@Override
	public void draw(Component component, int x, int y, int width, int height,
			boolean shouldValidate) {
		impl.draw(component, x, y, width, height, shouldValidate);
		
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#clipRect(int, int, int, int)
	 */
	@Override
	public void clipRect(int x, int y, int width, int height) {
		impl.clipRect(x, y, width, height);
	}



	/* (non-Javadoc)
	 * @see awt.client.Graphics#getSize()
	 */
	@Override
	public Dimension getSize() {
		return new Dimension(width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setSize(awt.client.Dimension)
	 */
	@Override
	public void setSize(Dimension size) {
		setWidth(size.width);
		setHeight(size.height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setHeight(int)
	 */
	@Override
	public void setHeight(int height) {
		setHeight(String.valueOf(height + "px"));
		impl.setHeight(height);
		this.height = height;

	}
	/* (non-Javadoc)
	 * @see awt.client.Graphics#setWidth(int)
	 */
	@Override
	public void setWidth(int width) {
		setWidth(String.valueOf(width + "px"));
		impl.setWidth(width);
		this.width = width;
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#cubicCurveTo(double, double, double, double, double, double)
	 */
	@Override
	public void cubicCurveTo(double cp1x, double cp1y, double cp2x,
			double cp2y, double x, double y) {
		impl.cubicCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#quadraticCurveTo(double, double, double, double)
	 */
	@Override
	public void quadraticCurveTo(double cpx, double cpy, double x, double y) {
		impl.quadraticCurveTo(cpx, cpy, x, y);
	}


	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#closePath()
	 */
	@Override
	public void closePath() {
		impl.closePath();
	}



	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#beginPath()
	 */
	@Override
	public void beginPath() {
		impl.beginPath();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setSize(int, int)
	 */
	@Override
	public void setSize(int width, int height) {
		setPixelSize(width, height);
		impl.setPixelSize(width, height);
		this.width = width;
		this.height = height;
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#copyArea(int, int, int, int, int, int)
	 */
	@Override
	public void copyArea(int x, int y, int width, int height, int dx, int dy) {
		impl.copyArea(x, y, width, height, dx, dy);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#dispose()
	 */
	@Override
	public void dispose() {
		impl.dispose();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#draw(awt.client.Shape)
	 */
	@Override
	public void draw(Shape s) {
		impl.draw(s);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawArc(int, int, int, int, int, int)
	 */
	@Override
	public void drawArc(int x, int y, int width, int height, int startAngle,
			int arcAngle) {
		impl.drawArc(x, y, width, height, startAngle, arcAngle);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#drawImage(com.google.gwt.user.client.ui.Image, awt.client.geom.AffineTransform)
	 */
	@Override
	public boolean drawImage(Image img, AffineTransform xform) {
		return impl.drawImage(img, xform);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int)
	 */
	@Override
	public boolean drawImage(Image img, int x, int y) {
		return impl.drawImage(img, x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int, awt.client.Color)
	 */
	@Override
	public boolean drawImage(Image img, int x, int y, Color bgcolor) {
		return impl.drawImage(img, x, y, bgcolor);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int, int, int)
	 */
	@Override
	public boolean drawImage(Image img, int x, int y, int width, int height) {
		return impl.drawImage(img, x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int, int, int, awt.client.Color)
	 */
	@Override
	public boolean drawImage(Image img, int x, int y, int width, int height,
			Color bgcolor) {
		return impl.drawImage(img, x, y, width, height, bgcolor);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int, int, int, int, int, int, int)
	 */
	@Override
	public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
			int sx1, int sy1, int sx2, int sy2) {
		return impl.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawImage(com.google.gwt.user.client.ui.Image, int, int, int, int, int, int, int, int, awt.client.Color)
	 */
	@Override
	public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
			int sx1, int sy1, int sx2, int sy2, Color bgcolor) {
		return impl.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawLine(int, int, int, int)
	 */
	@Override
	public void drawLine(int x1, int y1, int x2, int y2) {
		impl.drawLine(x1, y1, x2, y2);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawOval(int, int, int, int)
	 */
	@Override
	public void drawOval(int x, int y, int width, int height) {
		impl.drawOval(x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawPolygon(int[], int[], int)
	 */
	@Override
	public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
		impl.drawPolygon(xPoints, yPoints, nPoints);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawPolyline(int[], int[], int)
	 */
	@Override
	public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
		impl.drawPolyline(xPoints, yPoints, nPoints);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#drawRoundRect(int, int, int, int, int, int)
	 */
	@Override
	public void drawRoundRect(int x, int y, int width, int height,
			int arcWidth, int arcHeight) {
		impl.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#drawString(java.lang.String, float, float)
	 */
	@Override
	public void drawString(String s, float x, float y) {
		impl.drawString(s, x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#drawString(java.lang.String, int, int)
	 */
	@Override
	public void drawString(String str, int x, int y) {
		impl.drawString(str, x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#fill(awt.client.Shape)
	 */
	@Override
	public void fill(Shape s) {
		impl.fill(s);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#fillArc(int, int, int, int, int, int)
	 */
	@Override
	public void fillArc(int x, int y, int width, int height, int startAngle,
			int arcAngle) {
		impl.fillArc(x, y, width, height, startAngle, arcAngle);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#fillOval(int, int, int, int)
	 */
	@Override
	public void fillOval(int x, int y, int width, int height) {
		impl.fillOval(x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#fillPolygon(int[], int[], int)
	 */
	@Override
	public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
		impl.fillPolygon(xPoints, yPoints, nPoints);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#fillRect(int, int, int, int)
	 */
	@Override
	public void fillRect(int x, int y, int width, int height) {
		impl.fillRect(x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#fillRoundRect(int, int, int, int, int, int)
	 */
	@Override
	public void fillRoundRect(int x, int y, int width, int height,
			int arcWidth, int arcHeight) {
		impl.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#getBackground()
	 */
	@Override
	public Color getBackground() {
		return impl.getBackground();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getClip()
	 */
	@Override
	public Shape getClip() {
		return impl.getClip();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getClipBounds()
	 */
	@Override
	public Rectangle getClipBounds() {
		return impl.getClipBounds();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getColor()
	 */
	@Override
	public Color getColor() {
		return impl.getColor();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getElement()
	 */
	@Override
	public Element getElement() {
		return container;
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getFont()
	 */
	@Override
	public Font getFont() {
		return impl.getFont();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getFontMetrics(awt.client.Font)
	 */
	@Override
	public FontMetrics getFontMetrics(Font f) {
		return impl.getFontMetrics(f);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#getPaint()
	 */
	@Override
	public Paint getPaint() {
		return impl.getPaint();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#getStroke()
	 */
	@Override
	public Stroke getStroke() {
		return impl.getStroke();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#getTransform()
	 */
	@Override
	public AffineTransform getTransform() {
		return impl.getTransform();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#hit(awt.client.Rectangle, awt.client.Shape, boolean)
	 */
	@Override
	public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
		return impl.hit(rect, s, onStroke);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#rotate(double)
	 */
	@Override
	public void rotate(double theta) {
		impl.rotate(theta);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#rotate(double, double, double)
	 */
	@Override
	public void rotate(double theta, double x, double y) {
		impl.rotate(theta, x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#scale(double, double)
	 */
	@Override
	public void scale(double sx, double sy) {
		impl.scale(sx, sy);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#setBackground(awt.client.Color)
	 */
	@Override
	public void setBackground(Color color) {
		impl.setBackground(color);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setClip(int, int, int, int)
	 */
	@Override
	public void setClip(int x, int y, int width, int height) {
		impl.setClip(x, y, width, height);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setClip(awt.client.Shape)
	 */
	@Override
	public void setClip(Shape clip) {
		impl.setClip(clip);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setColor(awt.client.Color)
	 */
	@Override
	public void setColor(Color c) {
		impl.setColor(c);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setFont(awt.client.Font)
	 */
	@Override
	public void setFont(Font font) {
		impl.setFont(font);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#setPaint(awt.client.Paint)
	 */
	@Override
	public void setPaint(Paint paint) {
		impl.setPaint(paint);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setPaintMode()
	 */
	@Override
	public void setPaintMode() {
		impl.setPaintMode();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#setStroke(awt.client.Stroke)
	 */
	@Override
	public void setStroke(Stroke s) {
		impl.setStroke(s);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#setTransform(awt.client.geom.AffineTransform)
	 */
	@Override
	public void setTransform(AffineTransform Tx) {
		impl.setTransform(Tx);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setXORMode(awt.client.Color)
	 */
	@Override
	public void setXORMode(Color c1) {
		impl.setXORMode(c1);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#shear(double, double)
	 */
	@Override
	public void shear(double shx, double shy) {
		impl.shear(shx, shy);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#transform(awt.client.geom.AffineTransform)
	 */
	@Override
	public void transform(AffineTransform Tx) {
		impl.transform(Tx);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#translate(double, double)
	 */
	@Override
	public void translate(double tx, double ty) {
		impl.translate(tx, ty);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#translate(int, int)
	 */
	@Override
	public void translate(int x, int y) {
		impl.translate(x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#fill()
	 */
	@Override
	public void fill() {
		impl.fill();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#lineTo(double, double)
	 */
	@Override
	public void lineTo(double x, double y) {
		impl.lineTo(x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics2D#moveTo(double, double)
	 */
	@Override
	public void moveTo(double x, double y) {
		impl.moveTo(x, y);
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#getOpacity()
	 */
	@Override
	public double getOpacity() {
		return impl.getOpacity();
	}

	/* (non-Javadoc)
	 * @see awt.client.Graphics#setOpacity(double)
	 */
	@Override
	public void setOpacity(double opacity) {
		impl.setOpacity(opacity);
	}

	@Override
	public void stroke() {
		impl.stroke();
	}

}
